package com.zztpc.ljl.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.zztpc.ljl.myapplication.entity.UserFactory;
import com.zztpc.ljl.myapplication.service.UserFactoryService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getUserFactory();
    }

    private void getUserFactory() {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://zuowen.api.juhe.cn/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        UserFactoryService userFactoryService = retrofit.create(UserFactoryService.class);

        Call<UserFactory> info = userFactoryService.getInfo(2);

        info.enqueue(new Callback<UserFactory>() {
            @Override
            public void onResponse(Call<UserFactory> call, Response<UserFactory> response) {
                UserFactory userFactory =response.body();
                Log.d(TAG, "onResponse: "+userFactory.getResult().get(0).getName());
            }

            @Override
            public void onFailure(Call<UserFactory> call, Throwable t) {

            }
        });
    }
}
